<?php
namespace  app\common\service;
use app\common\service\token\driver\AdminToken;
use app\common\service\token\driver\AppToken;
use app\common\service\token\driver\OauthToken;

/**
 * 对外调用的服务层
 * Class TokenService
 * @package app\api\service
 */
class TokenService{
    protected $class = [];
    protected $conValue = '';//__construct值
    protected $alias = [
        'ad'=>AdminToken::class,
        'ap'=>AppToken::class,
        'qa'=>OauthToken::class,
    ];//调用那个token文件


    public function __construct($class){
        if(isset($this->alias[$class['type']])){
            $this->class = $this->alias[$class['type']];
        }else{
            $this->class = $class['type'];
        }
        $this->conValue = $class['conValue'];//__construct值
    }

    private function createInst(){
        //导入容器
        return app($this->class,[$this->conValue],true);
    }

    /**
     * 可修改为__callStatic
     * @param $functionName
     * @param $arguments
     * @return mixed
     */
    public function __call($functionName, $arguments){

        return call_user_func_array([self::createInst(), $functionName], $arguments);

    }

}